package com.majun.huaxishe.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.majun.huaxishe.entity.Theme;
import com.majun.huaxishe.entity.dto.ThemeDTO;
import com.majun.huaxishe.entity.vo.ThemeVO;
import com.majun.huaxishe.result.Result;
import com.majun.huaxishe.service.IThemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 主题表 前端控制器
 * </p>
 *
 * @author 马骏
 * @since 2024-02-29
 */
@RestController
@RequestMapping("/theme")
@CrossOrigin
public class ThemeController {

    @Autowired
    private IThemeService themeService;

    @GetMapping("/queryAll")
    public Result<List<Theme>> queryAll(String type){
        List<Theme> themeList = themeService.queryAll(type);
        return Result.success(themeList);
    }

    @GetMapping("/queryPage")
    public Result<Page<ThemeVO>> queryPage(ThemeDTO themeDTO){
        Page<ThemeVO> themeList = themeService.queryPage(themeDTO);
        return Result.success(themeList);
    }

    @GetMapping("/queryById")
    public Result<Theme> queryById(@RequestParam("id") Integer id){
        Theme theme = themeService.getById(id);
        return Result.success(theme);
    }

    @PostMapping("/sameThemeName")
    public Result sameThemeName(@RequestBody Theme theme){
        themeService.sameAlbumName(theme);
        return Result.success();
    }

    @PostMapping("/updateTheme")
    public Result updateTheme(@RequestBody Theme theme){
        themeService.updateById(theme);
        return Result.success();
    }

    @PostMapping("/addTheme")
    public Result addTheme(@RequestBody Theme theme){
        themeService.save(theme);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        themeService.removeById(id);
        return Result.success();
    }
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody Theme theme){
        themeService.updateById(theme);
        return Result.success();
    }
}
